﻿using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class TabbedBlue : System.Web.UI.MasterPage
{
    /*
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			// menu lateral
			if (Page.User.IsInRole("Cliente"))
			{
				AreaDataSource.StartingNodeUrl = "~/Cliente/Default.aspx";
			}
			else
			{
				AreaDataSource.StartingNodeUrl = "~/Adm/Default.aspx";
			}

			// se for página de edição, não tem link de "Novo"
			if (Request.Path.IndexOf("Default.aspx", StringComparison.InvariantCultureIgnoreCase) == -1)
			{
				lnkNew.Visible = false;
			}

			//Implementações pontuais de não exibição do botão New
			//Relatórios
			if (Request.Path.IndexOf("Relatorios", StringComparison.InvariantCultureIgnoreCase) != -1 && lnkNew != null)
			{
				lnkNew.Visible = false;
			}

			// form css
			if (SiteMapPath1 != null)
			{
				SiteMapPath1.ItemCreated += new SiteMapNodeItemEventHandler(SiteMapPath1_ItemCreated);
			}
		}
	}
     */

    void SiteMapPath1_ItemCreated(object sender, SiteMapNodeItemEventArgs e)
    {
        SiteMapNodeItem item = e.Item;
        if (item.ItemType == SiteMapNodeItemType.Current)
        {
            //		h1PageTitle.InnerHtml = item.SiteMapNode.Title;
        }
    }

    protected void rptTopNavigation_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HtmlGenericControl liTab = (HtmlGenericControl)e.Item.FindControl("liTab");
            LinkButton lnkTab = (LinkButton)e.Item.FindControl("lnkTab");
            Literal litTab = (Literal)e.Item.FindControl("litTab");
            SiteMapNode tabNode = (SiteMapNode)e.Item.DataItem;
            SiteMapNode currentNode = null;//AreaDataSource.Provider.FindSiteMapNode(HttpContext.Current);

            if (currentNode == null)
            {
                Response.Write(Request.AppRelativeCurrentExecutionFilePath);
                return;
            }

            if (currentNode == tabNode || currentNode.IsDescendantOf(tabNode))
            {
                lnkTab.Visible = false;
                litTab.Visible = true;
                liTab.Attributes.Add("class", "active");

                //				SubAreaDataSource.StartingNodeOffset = 0;
                //				SubAreaDataSource.StartingNodeUrl = tabNode.Url;
            }
            else
            {
                lnkTab.Visible = true;
                litTab.Visible = false;
            }
        }
    }

    protected void rptTopNavigation_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "SetArea")
        {
            String key = (String)e.CommandArgument;

            /*			SiteMapNode node = AreaDataSource.Provider.FindSiteMapNodeFromKey(key);
                        String url;
                        if (String.IsNullOrEmpty(node.Url))
                        {
                            url = node.ChildNodes[0].Url;
                        }
                        else
                        {
                            url = node.Url;
                        }	
                        Response.Redirect(url);
             */
        }
    }
}
